<template><div><h2 id="安装mysql" tabindex="-1"><a class="header-anchor" href="#安装mysql"><span>安装mysql</span></a></h2>
<h3 id="ubuntu24-mysql8-0" tabindex="-1"><a class="header-anchor" href="#ubuntu24-mysql8-0"><span>Ubuntu24(mysql8.0)</span></a></h3>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> apt-get</span><span style="color:#98C379"> update</span><span style="color:#7F848E;font-style:italic"> # 更新安装包工具</span></span>
<span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> apt-get</span><span style="color:#98C379"> install</span><span style="color:#98C379"> mysql-server</span><span style="color:#7F848E;font-style:italic"> # 安装mysql 确认按y</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="启动mysql" tabindex="-1"><a class="header-anchor" href="#启动mysql"><span>启动mysql</span></a></h4>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> service</span><span style="color:#98C379"> mysql</span><span style="color:#98C379"> start</span><span style="color:#7F848E;font-style:italic"> # 启动mysql</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic"># sudo service mysql stop 停止mysql</span></span>
<span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> service</span><span style="color:#98C379"> mysql</span><span style="color:#98C379"> status</span><span style="color:#7F848E;font-style:italic"> # 查看mysql状态</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h4 id="mysql开机自启" tabindex="-1"><a class="header-anchor" href="#mysql开机自启"><span>mysql开机自启</span></a></h4>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> systemctl</span><span style="color:#98C379"> enable</span><span style="color:#98C379"> mysql</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h4 id="配置mysql登录权限" tabindex="-1"><a class="header-anchor" href="#配置mysql登录权限"><span>配置mysql登录权限</span></a></h4>
<h5 id="mysql登录" tabindex="-1"><a class="header-anchor" href="#mysql登录"><span>mysql登录</span></a></h5>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">mysql</span><span style="color:#D19A66"> -u</span><span style="color:#98C379"> root</span><span style="color:#D19A66"> -p</span><span style="color:#7F848E;font-style:italic"> # 第一登录没有密码，直接回车</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h5 id="设置root用户连接密码" tabindex="-1"><a class="header-anchor" href="#设置root用户连接密码"><span>设置root用户连接密码</span></a></h5>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">use</span><span style="color:#98C379"> mysql</span><span style="color:#ABB2BF">; </span><span style="color:#7F848E;font-style:italic"># 进入mysql</span></span>
<span class="line"></span>
<span class="line"><span style="color:#C678DD">select</span><span style="color:#E06C75"> host,</span><span style="color:#ABB2BF"> user, authentication_string from user; </span><span style="color:#7F848E;font-style:italic"># 查看需要修改的root用户数据</span></span>
<span class="line"></span>
<span class="line"><span style="color:#61AFEF">ALTER</span><span style="color:#98C379"> USER</span><span style="color:#98C379"> 'root'@'localhost'</span><span style="color:#98C379"> IDENTIFIED</span><span style="color:#98C379"> WITH</span><span style="color:#98C379"> mysql_native_password</span><span style="color:#98C379"> BY</span><span style="color:#98C379"> '设置新的密码'</span><span style="color:#ABB2BF">; </span><span style="color:#7F848E;font-style:italic"># 为root账号赋权</span></span>
<span class="line"></span>
<span class="line"><span style="color:#61AFEF">FLUSH</span><span style="color:#98C379"> PRIVILEGES</span><span style="color:#ABB2BF">; </span><span style="color:#7F848E;font-style:italic"># 刷新权限</span></span>
<span class="line"></span>
<span class="line"><span style="color:#56B6C2">exit</span><span style="color:#ABB2BF">;  </span><span style="color:#7F848E;font-style:italic"># 推出mysql控制台</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><h5 id="设置远程访问登录" tabindex="-1"><a class="header-anchor" href="#设置远程访问登录"><span>设置远程访问登录</span></a></h5>
<p>设置账号权限</p>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#7F848E;font-style:italic">#进入mysql</span></span>
<span class="line"><span style="color:#61AFEF">use</span><span style="color:#98C379"> mysql</span><span style="color:#ABB2BF">;</span></span>
<span class="line"><span style="color:#ABB2BF"> </span></span>
<span class="line"><span style="color:#7F848E;font-style:italic">#设置登录ip为%通配符，取消登录ip限制</span></span>
<span class="line"><span style="color:#61AFEF">update</span><span style="color:#98C379"> user</span><span style="color:#98C379"> set</span><span style="color:#98C379"> host</span><span style="color:#98C379"> =</span><span style="color:#98C379"> '%'</span><span style="color:#98C379"> where</span><span style="color:#98C379"> user</span><span style="color:#98C379"> =</span><span style="color:#98C379"> 'root'</span><span style="color:#98C379"> and</span><span style="color:#98C379"> host</span><span style="color:#98C379"> =</span><span style="color:#98C379"> 'localhost'</span><span style="color:#ABB2BF">;</span></span>
<span class="line"><span style="color:#ABB2BF"> </span></span>
<span class="line"><span style="color:#7F848E;font-style:italic">#刷新权限</span></span>
<span class="line"><span style="color:#61AFEF">FLUSH</span><span style="color:#98C379"> PRIVILEGES</span><span style="color:#ABB2BF">;</span></span>
<span class="line"><span style="color:#ABB2BF"> </span></span>
<span class="line"><span style="color:#7F848E;font-style:italic">#查看数据情况</span></span>
<span class="line"><span style="color:#C678DD">select</span><span style="color:#E06C75"> host,</span><span style="color:#ABB2BF"> user, authentication_string from user;</span></span>
<span class="line"><span style="color:#ABB2BF"> </span></span>
<span class="line"><span style="color:#7F848E;font-style:italic">#退出mysql控制台</span></span>
<span class="line"><span style="color:#56B6C2">exit</span><span style="color:#ABB2BF">;</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>修改配置文件</p>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#7F848E;font-style:italic">#修改mysql配置文件，取消对远程ip为127.0.0.1的绑定</span></span>
<span class="line"><span style="color:#7F848E;font-style:italic">#将bind-address、mysqlx-bind-address这两行注释掉</span></span>
<span class="line"><span style="color:#61AFEF">vim</span><span style="color:#98C379"> /etc/mysql/mysql.conf.d/mysqld.cnf</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div><div class="line-number"></div></div></div><p>重启mysql</p>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">service</span><span style="color:#98C379"> mysql</span><span style="color:#98C379"> restart</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h4 id="防火墙放行" tabindex="-1"><a class="header-anchor" href="#防火墙放行"><span>防火墙放行</span></a></h4>
<p>如果是云服务器，还需要在安全组中开放3306端口</p>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#7F848E;font-style:italic">#服务器防火墙开放3306端口</span></span>
<span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> ufw</span><span style="color:#98C379"> allow</span><span style="color:#98C379"> 3306/tcp</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div><div class="line-number"></div></div></div><h2 id="安装docker和docker-compose" tabindex="-1"><a class="header-anchor" href="#安装docker和docker-compose"><span>安装docker和docker-compose</span></a></h2>
<p>在Ubuntu系统上安装Docker和Docker Compose，可按以下步骤操作：</p>
<h3 id="安装-docker" tabindex="-1"><a class="header-anchor" href="#安装-docker"><span>安装 Docker</span></a></h3>
<ol>
<li><strong>更新软件包列表</strong></li>
</ol>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> apt</span><span style="color:#98C379"> update</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><ol start="2">
<li><strong>安装必要的依赖包</strong></li>
</ol>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> apt</span><span style="color:#98C379"> install</span><span style="color:#98C379"> apt-transport-https</span><span style="color:#98C379"> ca-certificates</span><span style="color:#98C379"> curl</span><span style="color:#98C379"> software-properties-common</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><ol start="3">
<li><strong>添加 Docker 的官方 GPG 密钥</strong></li>
</ol>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">curl</span><span style="color:#D19A66"> -fsSL</span><span style="color:#98C379"> https://download.docker.com/linux/ubuntu/gpg</span><span style="color:#ABB2BF"> | </span><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> gpg</span><span style="color:#D19A66"> --dearmor</span><span style="color:#D19A66"> -o</span><span style="color:#98C379"> /usr/share/keyrings/docker-archive-keyring.gpg</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><ol start="4">
<li><strong>添加 Docker 软件源</strong></li>
</ol>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#56B6C2">echo</span><span style="color:#98C379"> "deb [arch=$(</span><span style="color:#61AFEF">dpkg</span><span style="color:#D19A66"> --print-architecture</span><span style="color:#98C379">) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/ubuntu $(</span><span style="color:#61AFEF">lsb_release</span><span style="color:#D19A66"> -cs</span><span style="color:#98C379">) stable"</span><span style="color:#ABB2BF"> | </span><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> tee</span><span style="color:#98C379"> /etc/apt/sources.list.d/docker.list</span><span style="color:#ABB2BF"> > </span><span style="color:#98C379">/dev/null</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><ol start="5">
<li><strong>再次更新软件包列表</strong></li>
</ol>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> apt</span><span style="color:#98C379"> update</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><ol start="6">
<li><strong>安装 Docker 引擎</strong></li>
</ol>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> apt</span><span style="color:#98C379"> install</span><span style="color:#98C379"> docker-ce</span><span style="color:#98C379"> docker-ce-cli</span><span style="color:#98C379"> containerd.io</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><ol start="7">
<li><strong>验证 Docker 是否安装成功</strong></li>
</ol>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> docker</span><span style="color:#98C379"> run</span><span style="color:#98C379"> hello-world</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><h3 id="安装-docker-compose" tabindex="-1"><a class="header-anchor" href="#安装-docker-compose"><span>安装 Docker Compose</span></a></h3>
<ol>
<li><strong>下载 Docker Compose 的最新稳定版本</strong></li>
</ol>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> curl</span><span style="color:#D19A66"> -L</span><span style="color:#98C379"> "https://github.com/docker/compose/releases/download/v2.17.3/docker-compose-$(</span><span style="color:#61AFEF">uname</span><span style="color:#D19A66"> -s</span><span style="color:#98C379">)-$(</span><span style="color:#61AFEF">uname</span><span style="color:#D19A66"> -m</span><span style="color:#98C379">)"</span><span style="color:#D19A66"> -o</span><span style="color:#98C379"> /usr/local/bin/docker-compose</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><ol start="2">
<li><strong>赋予执行权限</strong></li>
</ol>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">sudo</span><span style="color:#98C379"> chmod</span><span style="color:#98C379"> +x</span><span style="color:#98C379"> /usr/local/bin/docker-compose</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div><ol start="3">
<li><strong>验证 Docker Compose 是否安装成功</strong></li>
</ol>
<div class="language-bash line-numbers-mode" data-highlighter="shiki" data-ext="bash" style="background-color:#282c34;color:#abb2bf"><pre class="shiki one-dark-pro vp-code" v-pre=""><code><span class="line"><span style="color:#61AFEF">docker-compose</span><span style="color:#D19A66"> --version</span></span></code></pre>
<div class="line-numbers" aria-hidden="true" style="counter-reset:line-number 0"><div class="line-number"></div></div></div></div></template>


